package com.qsmx.store.app.main.mem.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qsmx.store.app.R;
import com.qsmx.store.app.main.mem.entity.MemCardLostOrOpenEntity;
import com.qsmx.store.app.main.mem.holder.MemCardManagerLostOrOpenHolder;

import java.util.List;

public class MemCardManagerLostOrOpenAdapter extends RecyclerView.Adapter<MemCardManagerLostOrOpenHolder> {

    private Context mContext;

    private List<MemCardLostOrOpenEntity.ContentBean> mData;

    public MemCardManagerLostOrOpenAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setData(List<MemCardLostOrOpenEntity.ContentBean> mData) {
        this.mData = mData;
    }

    //定义接口
    public static interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    //声明自定义的监听接口
    private MemCardManagerLostOrOpenAdapter.OnItemClickListener monItemClickListener = null;

    //提供set方法
    public void setonItemClickListener(MemCardManagerLostOrOpenAdapter.OnItemClickListener listener) {
        this.monItemClickListener = listener;
    }


    @NonNull
    @Override
    public MemCardManagerLostOrOpenHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        MemCardManagerLostOrOpenHolder holder = new MemCardManagerLostOrOpenHolder(LayoutInflater.from(mContext).inflate(R.layout.adapter_mem_card_manager_lost_or_open_list, viewGroup, false));
        return holder;


    }

    @Override
    public void onBindViewHolder(@NonNull MemCardManagerLostOrOpenHolder holder, final int position) {

        MemCardLostOrOpenEntity.ContentBean data = mData.get(position);
        holder.tvMemCardNum.setText(data.getIcCard().getMemberNo());
        holder.tvMemIcNum.setText(String.valueOf(data.getIcCard().getIcNo()));
        holder.tvName.setText(data.getMemberName());
        holder.tvPersonNum.setText(data.getMemberIdCard());
        if (data.getIcCard().getIcStatus() == 1) {
            holder.tvDoInfo.setVisibility(View.VISIBLE);
            holder.tvCardStatus.setText("正常");
            holder.tvDoInfo.setText("挂失");
        } else if (data.getIcCard().getIcStatus() == 2) {
            holder.tvDoInfo.setVisibility(View.VISIBLE);
            holder.tvCardStatus.setText("暂停使用");
            holder.tvDoInfo.setText("激活");
        } else if (data.getIcCard().getIcStatus() == 3) {
            holder.tvCardStatus.setText("锁卡");
            holder.tvDoInfo.setVisibility(View.GONE);
        } else if (data.getIcCard().getIcStatus() == 4) {
            holder.tvCardStatus.setText("已换卡");
            holder.tvDoInfo.setVisibility(View.GONE);
        } else if (data.getIcCard().getIcStatus() == 5) {
            holder.tvCardStatus.setText("已作废");
            holder.tvDoInfo.setVisibility(View.GONE);
        }

        holder.tvDoInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                monItemClickListener.onItemClick(v, position);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (mData != null && mData.size() > 0) {
            return mData.size();
        } else {
            return 0;
        }
    }
}
